#include "Comm.hpp"

int main()
{
    // 1、获取key
    key_t key = getShmkey();
    cout << "key_t: " << key << endl;
    //sleep(2);

    // 2、创建共享内存
    int shmid = Createshm(key, defaultsize);
    cout << "shmid: " << shmid << endl;
    //sleep(2);

    // ShmDebug(shmid);

    // 4、共享内存与进程的挂接
    char *addr = (char *)ShmAttach(shmid);
    cout << "attch success, addr: " << &addr << endl;
    //sleep(5);

    //进程间通信
    for(;;)
    {
        cout<<"addr message: "<<addr<<endl;
        sleep(1);
    }

    ShmDetach(addr);
    cout << "detach success, addr: " << &addr << endl;

    //sleep(5);
    // 3、删除共享内存
    deleteShm(shmid);
    return 0;
}